package com.zhangyu.shadow.repair.delegate.luncher;

import com.alibaba.fastjson.TypeReference;
import com.zhangyu.shadow.repair.base.IStringDataConvert;
import com.zhangyu.shadow.repair.config.RequestUrls;
import com.zhangyu.shadow.repair.delegate.bean.SetInfoBean;
import com.zhangyu.shadow.repair.manager.AccountManager;

import io.reactivex.disposables.Disposable;
import st.lib.base.net.callback.IError;
import st.lib.base.net.callback.ISuccess;
import st.lib.base.net.rx.RxRestClient;
import st.lib.base.ui.recycler.ObjConverter;

/**
 * Description:
 *
 * @author Hequn.Lee
 * @date 2018/11/5
 */
public class LauncherModel implements LauncherContract.Model {

    @Override
    public Disposable getPersonInfo(final IStringDataConvert<SetInfoBean> convert,
                                    IError error) {
        return RxRestClient.builder()
                .url(RequestUrls.URL_GET_INFO)
                .params(AccountManager.getInstance().getBaseInfo())
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        convert.convert(convertLoginBean(response));
                    }
                })
                .error(error)
                .build()
                .post();
    }

    @Override
    public Disposable getCanEditTime(final IStringDataConvert<String> success, IError error) {
        return RxRestClient.builder()
                .url(RequestUrls.URL_CAN_EDIT_START_ADN_END_TIME)
                .params(AccountManager.getInstance().getBaseInfo())
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        success.convert(response);
                    }
                })
                .error(error)
                .build()
                .post();
    }

    private SetInfoBean convertLoginBean(String response) {
        return new ObjConverter<SetInfoBean>().convert(response
                , new TypeReference<SetInfoBean>() {
                });
    }


}
